package com.bank.backend.boot.server.service.impl;


import com.bank.backend.boot.base.constant.ExceptionConstant;
import com.bank.backend.boot.base.model.dto.BankBranchDTO;
import com.bank.backend.boot.base.model.entity.BankBranch;
import com.bank.backend.boot.base.model.exception.GlobalException;
import com.bank.backend.boot.server.converter.BankBranchConverter;
import com.bank.backend.boot.server.mapper.BankBranchMapper;
import com.bank.backend.boot.server.service.BankBranchService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author JiaoWei
* @description 针对表【bank_branch(银行支行)】的数据库操作Service实现
* @createDate 2025-03-24 19:01:27
*/
@Service
public class BankBranchServiceImpl extends ServiceImpl<BankBranchMapper, BankBranch>
    implements BankBranchService {


    @Resource
    private BankBranchMapper bankBranchMapper;

    @Resource
    private BankBranchConverter bankBranchConverter;

    /**
     * 保存银行支行信息
     * @param bankBranchDTO
     * @return
     */
    @Override
    public boolean saveBankBranch(BankBranchDTO bankBranchDTO) {
        if (null == bankBranchDTO) {
            throw new GlobalException(ExceptionConstant.PARAM_ERROR);
        }

        String name = bankBranchDTO.getName();
        if (null == name) {
            throw new GlobalException(ExceptionConstant.NAME_NULL);
        }

        BankBranch bankBranch = bankBranchMapper.queryBankBranchByName(name);
        if (null != bankBranch) {
            throw new GlobalException(ExceptionConstant.NAME_EXIST);
        }
        BankBranch convert = bankBranchConverter.convert(bankBranchDTO);
        convert.setCreateTime(new Date());
        convert.setUpdateTime(new Date());
        int i = bankBranchMapper.insert(convert);
        if (i == 0) {
            return false;
        }
        return true;
    }
}




